package com.hnzq.cloud.freshuserassembly.mapper;

import com.hnzq.cloud.freshuserassembly.domain.FreResource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 周皓月
 * @since 2022-02-03
 */
public interface FreResourceMapper extends BaseMapper<FreResource> {


    /**
     * 查询当前用户角色的所有资源
     * @param userId
     * @return
     */
    @Select("SELECT resource_uri from fre_resource frs\n" +
            "JOIN\n" +
            "(select resource_id resourceId from fre_user fuser \n" +
            "JOIN\n" +
            "fre_role_resource fresource \n" +
            "ON\n" +
            "fuser.role_id = fresource.role_id where user_id = #{userId})t1\n" +
            "ON\n" +
            "frs.resource_id = t1.resourceId")
    List<String> findResourceUris(@Param("userId") Integer userId);

}
